package com.group.eams.controller;






import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.FixedAssetDetailQueryDto;
import com.group.eams.pojo.dto.PurchaseAcceptQueryDto;
import com.group.eams.pojo.entity.PurchaseAccept;
import com.group.eams.pojo.entity.PurchaseAccept;
import com.group.eams.pojo.entity.PurchaseAccept;
import com.group.eams.pojo.vo.FixedAssetDetailListVo;
import com.group.eams.pojo.vo.PurchaseAcceptListVo;
import com.group.eams.service.PurchaseAcceptService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 采购验收表(PurchaseAccept)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:29
 */
@RestController
@RequestMapping("/purchaseAccept")
public class PurchaseAcceptController  {
    /**
     * 服务对象
     */
    @Autowired
    private PurchaseAcceptService purchaseAcceptService;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "采购验收列表")
    public Result List(PurchaseAcceptQueryDto purchaseAcceptQueryDto){
        Page<PurchaseAccept> page = new Page<>(purchaseAcceptQueryDto.getPage(), purchaseAcceptQueryDto.getLimit());

        Page<PurchaseAcceptListVo> listVoPage = purchaseAcceptService.findPurchaseAcceptList(page, purchaseAcceptQueryDto);

        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/find",method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询采购验收信息")
    public Result find(@RequestParam Long id){
        PurchaseAccept purchaseAccept = purchaseAcceptService.getById(id);
        return Result.buildSuccess(purchaseAccept);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加采购验收信息")
    public Result add(@RequestBody PurchaseAccept purchaseAccept){
        boolean result = purchaseAcceptService.save(purchaseAccept);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "修改采购验收信息")
    public Result update(@RequestBody PurchaseAccept purchaseAccept){
        boolean result = purchaseAcceptService.updateById(purchaseAccept);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @ApiOperation(value = "删除采购验收信息")
    public Result add(@RequestParam Long id){
        boolean result = purchaseAcceptService.removeById(id);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有采购验收信息")
    public Result findAll(){
        List<PurchaseAccept> purchaseAcceptList = purchaseAcceptService.list();
        return Result.buildSuccess(purchaseAcceptList);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    @ApiOperation(value = "批量删除信息")
    public Result batchRemove(@RequestBody BatchDeleteDto batchDeleteDto){
        boolean result = purchaseAcceptService.removeByIds(batchDeleteDto.getIds());
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }



    @RequestMapping(value = "/findByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据申请编号查询采购验收信息")
    public Result findByApplicationNum(@RequestParam String applicationNum){
        PurchaseAccept purchaseAccept = purchaseAcceptService.findByApplicationNum(applicationNum);
        return Result.buildSuccess(purchaseAccept);
    }

    @RequestMapping(value = "/assetDetail",method = RequestMethod.GET)
    @ApiOperation(value = "采购验收资产明细")
    public Result assetList(FixedAssetDetailQueryDto fixedAssetDetailQueryDto){
        Page<FixedAssetDetailListVo> page = new Page<>(fixedAssetDetailQueryDto.getPage(), fixedAssetDetailQueryDto.getLimit());
        Page<FixedAssetDetailListVo> listVoPage = purchaseAcceptService.findByQueryDto(page, fixedAssetDetailQueryDto);
        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量添加采购验收信息")
    public Result addBatch(@RequestBody List<PurchaseAccept> purchaseAcceptList){
        boolean result = purchaseAcceptService.saveBatch(purchaseAcceptList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量修改采购验收信息")
    public Result updateBatch(@RequestBody List<PurchaseAccept> purchaseAcceptList){
        boolean result = purchaseAcceptService.updateBatchById(purchaseAcceptList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    
}

